home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / Color Window Demo / do scrolling.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-31  |  9.9 KB  |  193 lines  |  [TEXT/KAHL]

  1. /*
  2.     this modual contains all the routines to handle the scrolling of a window.
  3.     This routine is called from the "do mouse" modual.
  4. */
  5.  
  6.  
  7. #include "my color.h"
  8. pascal void up_action(ControlHandle, short);
  9. pascal void down_action(ControlHandle, short);
  10. pascal void page_up_action(ControlHandle, short);
  11. pascal void page_down_action(ControlHandle, short);
  12. pascal void thumb_action(void);
  13.  
  14. Boolean    do_controls(the_window, where)    /* the_window is, obviously, the window that is 
  15.                                             active, "where" is the point where the mouse 
  16.                                             was clicked, in global cooridiates, inside 
  17.                                             the active window. do_controls() will return 
  18.                                             TRUE is a control was clicked in otherwise 
  19.                                             it will return FALSE */ 
  20. CWindowPtr    the_window;
  21. Point        where;
  22. {
  23. short            part_code, new_value, which_control, old_value;
  24. short            scroll_amount;
  25. ControlHandle    the_control;
  26. CWindowPeek        owner_window;
  27.  
  28.     GlobalToLocal(&where);                /* first convert the mouse location to local coordinates */
  29.     part_code = FindControl(where, the_window, &the_control);    /* now find out what part
  30.                                                                     of the window was clicked in */
  31.     if(!part_code)    return FALSE;        /* if part_code is NULL, then the scroll bars 
  32.                                             were not clicked in */
  33.     switch(part_code)
  34.     {
  35.         case inUpButton:    /* the user clicked in the UP arrow of the scroll bar */
  36.             TrackControl(the_control, where, up_action);
  37.             break;
  38.             
  39.         case inDownButton:    /* the user clicked in the DOWN arrow of the scroll bar */
  40.             TrackControl(the_control, where, down_action);
  41.             break;
  42.         
  43.         case inPageUp:        /* the user is clicking in the page up region of the scroll bar */
  44.             TrackControl(the_control, where, page_up_action);
  45.             break;
  46.             
  47.         case inPageDown:    /* the user is clicking in the page down region of the scroll bar */
  48.             TrackControl(the_control, where, page_down_action);
  49.             break;
  50.         
  51.         case inThumb:        /* the user is draging the "thumb" around */
  52.             old_value = GetCtlValue(the_control);    /* this is the last value the control had before the current activity */
  53.             TrackControl(the_control, where, thumb_action);
  54.             new_value = GetCtlValue(the_control);    /* this is the last value the control had before the current activity */
  55.             owner_window = (CWindowPeek)(**the_control).contrlOwner;    /* I refere to the control's owning window so that I can easily get to the text edit record */
  56.             scroll_amount = old_value - new_value;
  57.             which_control = GetCRefCon(the_control);    /* this is the control that was clicked in */
  58.             if(which_control == VERTICLE_SCROLL)                    /* if we're in the verticle scroll bar move the text down */    
  59.                 TEScroll(0, scroll_amount, (TEHandle)owner_window->refCon);
  60.             else if (which_control == HORIZONTAL_SCROLL)            /* if we're in the horizontal scroll bar move the text to the left */
  61.                 TEScroll(scroll_amount, 0, (TEHandle)owner_window->refCon);
  62.             break;
  63.     
  64.         default:            /* default to a SysBeep 'cause that will mean something is wrong */
  65.             SysBeep(11);
  66.             break;
  67.     }
  68.     return TRUE;
  69. }
  70.  
  71.  
  72. pascal void up_action(control, part)    /* TrackControl will repeatedly call this 
  73.                                             routine as long as the mouse is held down
  74.                                             in the UP arrow of the scroll bar */
  75. ControlHandle    control;
  76. short            part;
  77. {
  78. short    old_control_value, scroll_units, control_min_value, new_control_value;
  79. CWindowPeek    owner_window;
  80. short    which_control;
  81.  
  82.     scroll_units = 1;        /* this is how many pixels I'll scroll the window */
  83.     which_control = GetCRefCon(control);    /* this is the control that was clicked in */
  84.     old_control_value = GetCtlValue(control);    /* this is the last value the control had before the current activity */
  85.     control_min_value = GetCtlMin(control);        /* this is the minimum valu the control can have, this was defined when the control was created */
  86.     new_control_value = old_control_value - scroll_units;    /* this is the new value that the control will have after the scrolling */
  87.     if(new_control_value < control_min_value)    /* if the new control value isn't legitimate */
  88.         SetCtlValue(control, control_min_value);/* just set the control to the minimum value */
  89.     else                                        /* else, set the control value to the new value, the scroll the text */
  90.     {
  91.         SetCtlValue(control, new_control_value);
  92.         owner_window = (CWindowPeek)(**control).contrlOwner;    /* I refere to the control's owning window so that I can easily get to the text edit record */
  93.         if(which_control == VERTICLE_SCROLL)                    /* if we're in the verticle scroll bar move the text down */    
  94.             TEScroll(0, scroll_units, (TEHandle)owner_window->refCon);
  95.         else if (which_control == HORIZONTAL_SCROLL)            /* if we're in the horizontal scroll bar move the text to the left */
  96.             TEScroll(scroll_units, 0, (TEHandle)owner_window->refCon);
  97.     }
  98. }
  99.  
  100. pascal void down_action(control, part)/* TrackControl will call this routine 
  101.                                         repeatedly as long as the mouse is held 
  102.                                         down in the DOWN arrow */
  103. ControlHandle    control;
  104. short            part;
  105. {
  106. short    old_control_value,  scroll_units, control_max_value, new_control_value;
  107. CWindowPeek    owner_window;
  108. short    which_control;
  109.  
  110.     scroll_units = 1;                            /* this is the number of pixels I'll scroll each time the routine is called */
  111.     which_control = GetCRefCon(control);        /* this is the control the mouse was pressed in */
  112.     old_control_value = GetCtlValue(control);    /* this is the value the controll had when it was last used */
  113.     control_max_value = GetCtlMax(control);        /* this is the maximum value the control can obtain, this was set when the control was defined */
  114.     new_control_value = old_control_value + scroll_units;    /* this is the value the control will be set to when we are done */
  115.     if(new_control_value > control_max_value)    /* if the new control value too large then just set the control to the maximum value */
  116.         SetCtlValue(control, control_max_value);
  117.     else                                        /* else set the controll to the new value and scroll the test */
  118.     {
  119.         SetCtlValue(control, new_control_value);
  120.         owner_window = (CWindowPeek)(**control).contrlOwner;    /* I refere to the control's owning window so that I can easily get to the text edit record */
  121.         if(which_control == VERTICLE_SCROLL)        /* if we are in the verticle scroll bar then scroll up */
  122.             TEScroll(0, -scroll_units, (TEHandle)owner_window->refCon);
  123.         else if (which_control == HORIZONTAL_SCROLL)    /* else if we're in the horizontal scroll bar, scroll to the left */
  124.             TEScroll( -scroll_units, 0, (TEHandle)owner_window->refCon);
  125.     }
  126. }
  127.  
  128. pascal void page_up_action(control, part)    /* TrackControl will repeatedly call this 
  129.                                                 routine as long as the mouse is held down
  130.                                                 in the PageUp region of the scroll bar */
  131. ControlHandle    control;
  132. short            part;
  133. {
  134. short    old_control_value,  scroll_units, control_min_value, new_control_value;
  135. CWindowPeek    owner_window;
  136. short    which_control;
  137.  
  138.     scroll_units = 45;                            /* this is the number of pixels I'll scroll each time this routine is called */
  139.     which_control = GetCRefCon(control);
  140.     old_control_value = GetCtlValue(control);    /* this is the value of the scroll bar from the last time it was used */
  141.     control_min_value = GetCtlMin(control);        /* this is the minimum value the scroll bar can obtain, this was set when the scroll bar was defined */
  142.     new_control_value = old_control_value - scroll_units; /* this is the new value for the control */
  143.     if(new_control_value < control_min_value) scroll_units = old_control_value - control_min_value;
  144.     if(old_control_value <= control_min_value)    /* if the new value is too small, just set the control to the minimum value */
  145.         SetCtlValue(control, control_min_value);
  146.     else                                        /* if everything is O.K., set the control to the new value, and scroll the window */
  147.     {
  148.         SetCtlValue(control, old_control_value - scroll_units);
  149.         owner_window = (CWindowPeek)(**control).contrlOwner; /* I refer to the control's owning window so that I can easily get to the text edit record */
  150.         if(which_control == VERTICLE_SCROLL)    /* if we're in the verticle scroll bar page area, then page down */
  151.             TEScroll(0, scroll_units, (TEHandle)owner_window->refCon);
  152.         else if (which_control == HORIZONTAL_SCROLL)    /* else if we are in the horizontal scroll bar, page right */
  153.             TEScroll(scroll_units, 0, (TEHandle)owner_window->refCon);
  154.     }
  155. }
  156.  
  157. pascal void page_down_action(control, part)    /* TrackControl will repeatedly call this 
  158.                                                 routine as long as the mouse is held down
  159.                                                 in the PageDown region of the scroll bar */
  160. ControlHandle    control;
  161. short            part;
  162. {
  163. short    old_control_value,  scroll_units, control_max_value, new_control_value;
  164. CWindowPeek    owner_window;
  165. short    which_control;
  166.  
  167.     scroll_units = 45;                        /* this is the amount I'll scroll each time this routine is acalled */
  168.     which_control = GetCRefCon(control);    /* this is the ID of scroll bar that was choosen */
  169.     old_control_value = GetCtlValue(control);/* this is the value of the scroll bar from the last time it was used */
  170.     control_max_value = GetCtlMax(control);    /* this is the maximum value the scroll bar can obtain */
  171.     new_control_value = old_control_value + scroll_units;    /* this is the new value for the scroll bar */
  172.     if(new_control_value > control_max_value) scroll_units = control_max_value - old_control_value;
  173.     if(old_control_value >= control_max_value)    /* if the new value is too large, then just set the control to the maximum value and leave */
  174.         SetCtlValue(control, control_max_value);
  175.     else                                    /* else set the control to the new value, and the  scroll the window */
  176.     {
  177.         SetCtlValue(control, new_control_value);
  178.         owner_window = (CWindowPeek)(**control).contrlOwner;    /* I refere to the control's owning window so that I can easily get to the text edit record */
  179.         if(which_control == VERTICLE_SCROLL)    /* if we are in the verticle scroll bar, then scroll up */
  180.             TEScroll(0, -scroll_units, (TEHandle)owner_window->refCon);
  181.         else if (which_control == HORIZONTAL_SCROLL)    /* if we are in the horizontal scroll bar then scroll to the left */
  182.             TEScroll(-scroll_units, 0, (TEHandle)owner_window->refCon);
  183.     }
  184. }
  185.  
  186. pascal void thumb_action()        /* I just put this here as an example, I don't have 
  187.                                     anything to do while the user is draging the 
  188.                                     "thumb" around */
  189. {
  190.     return;
  191. }
  192.  
  193.